<?php
/**
 * ProjectName: Grapes.
 * Created by LemonZ.
 * FileName: Articles.php
 * Date: 2019/2/14
 * Time: 21:24
 * Description:
 */

namespace app\api\controller;


use app\common\controller\Api;
use app\common\model\Article as ArticleModel;
use app\common\model\ArticleType;

class Articles extends Api
{
    /**
     * 获取全部文章分类列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getArticleType()
    {
        $articleType = new ArticleType();
        return $articleType->articleTypeList();
    }

    /**
     * 获取文章列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getArticleList()
    {
        $article = new ArticleModel();
        return $article->articleList(input('type_id/d', 0), input('page/d',1), input('limit/d',10));
    }

    /**
     * 获取单个文章的详细信息
     * @return array|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getArticleDetail()
    {
        $article_id = input('article_id/d', 0);
        if(!$article_id) return error_code(10051);
        $article = new ArticleModel();
        return $article->articleDetail($article_id);
    }
}